package com.bestdreamer;

public class FruitFactory {


    public static Fruit getApple(){
        return new Apple();
    }

    public static Fruit getBanana(){
        return new Banana();
    }


    public static Fruit getFruit(String type) throws IllegalAccessException, InstantiationException, ClassNotFoundException {

        /*
        if(type.equalsIgnoreCase("apple")){
            return Apple.class.newInstance();
        }else if(type.equalsIgnoreCase("banana")){
            return Banana.class.newInstance();
        }else{
            return null;
        }
        */

        Class fruit = Class.forName("com.bestdreamer."+type);
        return (Fruit)fruit.newInstance();
    }

}
